package com.zk.mall.servlet;

import com.zk.mall.entity.User;
import com.zk.mall.service.IUserService;
import com.zk.mall.service.impl.UserServiceImpl;
import javafx.scene.control.PasswordField;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet("/addUserServlet")
public class addUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username=request.getParameter("username");
        String userpwd=request.getParameter("userpwd");
        String userrealname=request.getParameter("userrealname");
        String usertel=request.getParameter("usertel");
        String useremail=request.getParameter("useremail");

        IUserService userService=new UserServiceImpl();
        User user=new User(username,userpwd,userrealname,usertel,useremail);
        int flag = userService.adduser(user);

        PrintWriter out=response.getWriter();
        if(flag>0){
            out.print("注册成功");
        }else {
            out.print("注册失败");
        }
    }
}
